home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / MacTechNotes / Platforms & Tools / Stand-Alone Code Folder / Persistƒ / Persist.p < prev    next >
Encoding:
Text File  |  1990-07-14  |  1.2 KB  |  45 lines  |  [TEXT/MPS ]

  1.  
  2. UNIT Persist;
  3.  
  4. { This is a stand-alone module which maintains a running total }
  5. { of the squares of the parameters it receives. This requires  }
  6. { the cooperation of a host application. The host must use     }
  7. { messages to tell the module when to initialize and when to   }
  8. { tear down. The host also must maintain a handle to the       }
  9. { module's A5 world between invocations.                       }
  10.  
  11. INTERFACE
  12.  
  13.     USES
  14.         Types, SAGlobals;
  15.     
  16.     CONST
  17.         kAccumulate = 0;    {These are the control messages.}
  18.         kFirstTime = 1;
  19.         kLastTime = 2;
  20.     
  21.     FUNCTION AccSquares (parm: Longint; message: Integer;
  22.                 VAR A5Ref: A5RefType) : Longint;
  23.  
  24. IMPLEMENTATION
  25.  
  26.     { Define global storage to retain a running }
  27.     { total over multiple calls to the module.  }
  28.     VAR accumulation : Longint;
  29.  
  30.     FUNCTION AccSquares (parm: Longint; message: Integer;
  31.                 VAR A5Ref: A5RefType) : Longint;
  32.     VAR
  33.         oldA5: Longint;
  34.     BEGIN
  35.         IF message = kFirstTime THEN MakeA5World(A5Ref);
  36.         oldA5 := SetA5World(A5Ref);
  37.             IF message = kFirstTime THEN accumulation := 0;
  38.             accumulation := accumulation + (parm * parm);
  39.             AccSquares := accumulation;
  40.         RestoreA5World(oldA5, A5Ref);
  41.         IF message = kLastTime THEN DisposeA5World(A5Ref);
  42.     END;
  43.     
  44. END.
  45.